<template>
  <div class="menu">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-button  @click="$router.push({name:'menu-create'})"
          >添加菜单</el-button
        >
      </div>
      <el-table
      :data="menus"
      style="width: 100%">
      <el-table-column
        type="index"
        label="编号"
        align="center">
      </el-table-column>
      <el-table-column
        prop="name"
        label="菜单名称"
        align="center">
      </el-table-column>

      <el-table-column
        prop="level"
        label="菜单级数"
        align="center">
      </el-table-column>

      <el-table-column
        prop="icon"
        label="前端图标"
        align="center">
      </el-table-column>

      <el-table-column
        prop="orderNum"
        label="排序"
        align="center">
      </el-table-column>

      <el-table-column
        prop="address"
        label="操作"
        align="center">
        <template slot-scope="scope">
             <el-link @click="handleEdit(scope.row)">编辑</el-link>
             &nbsp;
             <el-link @click="handleDelete(scope.row)">删除</el-link>
        </template>
      </el-table-column>
    </el-table>

    </el-card>
  </div>
</template>
<script lang="ts">
import Vue from 'vue'
import { getAllMenus, deleteMenu } from '@/service/menu'
export default Vue.extend({
  name: 'MenuCreate',
  data () {
    return {
      menus: []
    }
  },
  created () {
    this.loadAllMenu()
  },
  methods: {
    async loadAllMenu () {
      const { data } = await getAllMenus()
      if (data.code === '000000') {
        this.menus = data.data
      }
    },
    handleEdit (row:any) {
      this.$router.push({ name: 'menu-edit', params: { id: row.id } })
    },
    handleDelete (row:any) {
      this.$confirm('确认删除吗？', '删除提醒', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const { data } = await deleteMenu(row.id)
        if (data.code === '000000') {
          this.$message.success('删除成功')
          this.loadAllMenu()
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
})
</script>
<style scoped>

</style>
